package com.coffee.job.service.quartz.job;


import com.coffee.core.util.DateUtil;
import com.coffee.order.api.inquire.service.InquireOrderService;
import com.coffee.statistics.api.service.StatisticsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Nonnull;
import java.util.Date;


@DisallowConcurrentExecution
public class StatisticsJob extends QuartzJobBean {
    private static final Logger logger = LoggerFactory.getLogger(StatisticsJob.class);

    @DubboReference(check = false)
    private StatisticsService statisticsService;

    @Override
    protected void executeInternal(@Nonnull JobExecutionContext context) {
        logger.info("==========transactionFinash开始：" + DateUtil.getDateTime(new Date(), DateUtil.DEFAULT_DATETIME_FORMAT));
        try {
            for (int i = 0; i <= 30; i++) {
                Date minDate = DateUtil.setMinDate(DateUtil.addDays(new Date(), -i));
                Date maxDate = DateUtil.setMaxDate(DateUtil.addDays(new Date(), -i));
                statisticsService.addByDay(minDate, maxDate);
            }
            logger.info("==========transactionFinash结束：" + DateUtil.getDateTime(new Date(), DateUtil.DEFAULT_DATETIME_FORMAT));
        } catch (Exception e) {
            logger.info("==========transactionFinash失败==========", e);
        }
    }

}
